package de.baumann.browser.present

import de.baumann.browser.api.OdinObserver
import de.baumann.browser.api.net.vo.NodeDetail
import de.baumann.browser.base.BasePresenter
import de.baumann.browser.iview.INodeDetailView
import de.baumann.browser.model.NodeModel

class NodeDetailPresenter :BasePresenter<INodeDetailView>(){
private val nodeModel = NodeModel()

   fun nodeDetail(nodeId:String) {
        this.nodeModel.nodeDetail(nodeId)
                .subscribe(object : OdinObserver<NodeDetail>(view) {
                    override fun onSuccess(data: NodeDetail?) {
                        if (view == null || data==null) {
                            return
                        }
                        val node = data.nodeInfo
                        view.setHead(node.ownerAvatar)
                        view.setCreateTime(node.createTime)
                        view.setNodeMembers(node.headcount)
                        view.setNodeOwner(node.ownerName)
                        view.setTotalHash(node.totalContribute)
                        view.setPieChart(data.pieChart)
                        view.setLineChart(data.lineChart)
                    }
                })
    }
}